﻿ @using QLNS
@{
   
    string tree = "<div id='jqxTree1' style='float: left; margin-left: 0px;'>";

    List<PhongBan> root = QLNS.Models.PhongBanModels.GetDSPhongBan(0);
    if (root.Count > 0)
    {
        tree += "<ul>";
        //Cap 1 la Don vi       
        foreach (var r in root)
        {

            tree += "<li item-expanded='true' id='dept" + r.ID + "'>";
            tree += r.PhanLoai == 1 ? "<img src='/Content/images/icon_gperson.png' />" : "<img src='/Content/images/house.png' />";
            tree += r.TenPhongBan;
            List<PhongBan> root1 = QLNS.Models.PhongBanModels.GetDSPhongBan(r.ID);
            List<CanBo> dsCBroot = QLNS.Models.CanBoModels.GetDSCanBoOfPhongBan(r.ID);
            if (root1.Count > 0 || dsCBroot.Count > 0)
            {
                tree += "<ul>";
                foreach (var cb in dsCBroot)
                {
                    tree += "<li id='per" + cb.ID + "'><img src='/Content/images/icon_person.png' />" + cb.Ho + " " + cb.Ten;
                    tree += "</li>";
                }
                foreach (var r1 in root1)
                {

                    tree += "<li id='room" + r1.ID + "'>";
                    tree += r1.PhanLoai == 1 ? "<img src='/Content/images/icon_gperson.png' />" : "<img src='/Content/images/house.png' />";
                    tree += r1.TenPhongBan;
                    List<PhongBan> root2 = QLNS.Models.PhongBanModels.GetDSPhongBan(r1.ID);
                    List<CanBo> dsCBroot1 = QLNS.Models.CanBoModels.GetDSCanBoOfPhongBan(r1.ID);  
                    if (root2.Count > 0 || dsCBroot1.Count > 0)
                    {
                        tree += "<ul>";
                        foreach (var cb1 in dsCBroot1)
                        {
                            tree += "<li id='per" + cb1.ID + "'><img src='/Content/images/icon_person.png' />" + cb1.Ho + " " + cb1.Ten;
                            tree += "</li>";
                        }
                        foreach (var r2 in root2)
                        {
                            tree += "<li id='room" + r2.ID + "'>";
                            tree += r2.PhanLoai == 1 ? "<img src='/Content/images/icon_gperson.png' />" : "<img src='/Content/images/house.png' />";
                            tree += r2.TenPhongBan;
                            List<PhongBan> root3 = QLNS.Models.PhongBanModels.GetDSPhongBan(r2.ID);
                            List<CanBo> dsCBroot2 = QLNS.Models.CanBoModels.GetDSCanBoOfPhongBan(r2.ID);
                            if (root3.Count > 0 || dsCBroot2.Count > 0)
                            {
                                tree += "<ul>";
                                foreach (var cb2 in dsCBroot2)
                                {
                                    tree += "<li id='per" + cb2.ID + "'><img src='/Content/images/icon_person.png' />" + cb2.Ho + " " + cb2.Ten;
                                    tree += "</li>";
                                }
                                foreach (var r3 in root3)
                                {
                                    tree += "<li id='room" + r3.ID + "'>";
                                    tree += r3.PhanLoai == 1 ? "<img src='/Content/images/icon_gperson.png' />" : "<img src='/Content/images/house.png' />";
                                    tree += r3.TenPhongBan;
                                    List<PhongBan> root4 = QLNS.Models.PhongBanModels.GetDSPhongBan(r3.ID);
                                    List<CanBo> dsCBroot3 = QLNS.Models.CanBoModels.GetDSCanBoOfPhongBan(r3.ID);
                                    if (root4.Count > 0 || dsCBroot3.Count > 0)
                                    {
                                        tree += "<ul>";
                                        foreach (var cb3 in dsCBroot3)
                                        {
                                            tree += "<li id='per" + cb3.ID + "'><img src='/Content/images/icon_person.png' />" + cb3.Ho + " " + cb3.Ten;
                                            tree += "</li>";
                                        }
                                        foreach (var r4 in root4)
                                        {
                                            tree += "<li id='dept" + r4.ID + "'>";
                                            tree += r4.PhanLoai == 1 ? "<img src='/Content/images/icon_gperson.png' />" : "<img src='/Content/images/house.png' />";
                                            tree += r4.TenPhongBan;
                                            List<CanBo> dsCBroot4 = QLNS.Models.CanBoModels.GetDSCanBoOfPhongBan(r4.ID);
                                            if (dsCBroot4.Count > 0)
                                            {
                                                tree += "<ul>";
                                                foreach (var cb4 in dsCBroot4)
                                                {
                                                    tree += "<li id='per" + cb4.ID + "'><img src='/Content/images/icon_person.png' />" + cb4.Ho + " " + cb4.Ten;
                                                    tree += "</li>";
                                                }
                                                tree += "</ul>";
                                            }
                                            tree += "</li>";
                                        }
                                        tree += "</ul>";
                                    }
                                    tree += "</li>";

                                }
                                tree += "</ul>";
                            }

                            tree += "</li>";
                        }
                        tree += "</ul>";
                    }
                    else
                    {
                        tree += "</li>";
                    }
                }
                tree += "</ul>";
            }
            else
            {
                tree += "</li>";
            }
        }
        tree += "</ul>";
    }
    tree += "</div>";
}

<script type="text/javascript">
 
    $(document).ready(function () {
        var theme = getDemoTheme();
        // Create jqxTree
        $('#jqxTree1').jqxTree({ height: '600px', width: '95%', theme: theme });
        var contextMenu = $("#jqxMenu1").jqxMenu({ width: '200px', theme: theme, height: '450px', autoOpenPopup: false, mode: 'popup' });
        var contextMenu2 = $("#jqxMenu2").jqxMenu({ width: '200px', theme: theme, height: '100px', autoOpenPopup: false, mode: 'popup' });
        var clickedItem = null;
        var attachContextMenu = function () {
            // open the context menu when the user presses the mouse right button.
            $("#jqxTree1 li").on('mousedown', function (event) {
                var target = $(event.target).parents('li:first')[0];
                var leftClick = isLeftClick(event);
                if (leftClick && target != null) {
                    contextMenu.jqxMenu('close'); contextMenu2.jqxMenu('close');
                    $("#jqxTree1").jqxTree('selectItem', target);
                    var ItemContext = $('#jqxTree1').jqxTree('selectedItem');
                    var str = ItemContext.id;
                    if (ItemContext != null) {
                        if (str.substr(0, 3) == "per") {
                            $('#percontent').show();
                            $('#deptcontent').hide();
                            $('#roomcontent').hide();
                            $('#maincontent').hide();
                            $('#infoPerson').show();
                            $('#info').show();
                             $('#info1').show();
                            str = str.substr(3);
                            $.getJSON('/Pers/GetThongTinCanBo/'+str,null,
                            function(data){
                                $('#SoHieuCanBoCC').html(data[0].SoHieuCBCC);
                                $('#HoTenCBCC').html(data[0].Ho+' '+data[0].Ten);
                                $('#PhongBanCBCC').html(data[0].TenPhongBan);
                                $('#ChucVuCBCC').html(data[0].TenChucVu);
                                if(data[0].TrangThai==1){
                                    $('#TrangThaiCBCC').html("Đang làm việc");
                                } 
                                if(data[0].TrangThai==2){
                                   $('#TrangThaiCBCC').html("Chuyển công tác"); 
                                }
                                if(data[0].TrangThai==3){
                                   $('#TrangThaiCBCC').html("Nghỉ"); 
                                }
                                $('#NgaySinh').html(data[0].NgaySinh);
                                document.getElementById("HinhAnh").setAttribute("src", "http://"+window.location.host+'/'+data[0].Image);
                                $('#TrinhDoChuyenMonCBCC').html(data[0].TrinhDoChuyenMon);
                                $('#TrinhDoLyLuanChinhTriCBCC').html(data[0].TrinhDoLyLuan);
                                $('#TrinhDoNgoaiNguCBCC').html(data[0].TrinhDoNgoaiNgu);
                                $('#TrinhDoTinHocCBCC').html(data[0].TrinhDoTinHoc);
                                $('#TrinhDoQuanLyNhaNuocCBCC').html(data[0].TrinhDoQLNN);
                                $('#BacLuong').html(data[0].BacLuong);
                                $('#HeSoLuong').html(data[0].HeSoLuong);
                                $('#NgachCongChucCBCC').html(data[0].TenNgach);
                                $('#MaNgachCBCC').html(data[0].MaNgachCC);
                                if(data[0].NgayVaoDang==''){
                                    $('#NgayVaoDangCBCC').html("Chưa Vào Đảng");
                                } else {
                                    $('#NgayVaoDangCBCC').html(data[0].NgayVaoDang);
                                }
                                if(data[0].NgayVaoChinhThuc==''){
                                    $('#NgayVaoChinhThucCBCC').html("Chưa Vào Đảng");
                                } else {
                                    $('#NgayVaoChinhThucCBCC').html(data[0].NgayVaoChinhThuc);
                                }
                                if(data[0].NgayVaoDoan==''){
                                    $('#NgayVaoDoanCBCC').html("Chưa Vào Đoàn");
                                } else {
                                    $('#NgayVaoDoanCBCC').html(data[0].NgayVaoDoan);
                                }
                                
                            });
                          
                        } else if (str.substr(0, 4) == "dept") {
                            $('#percontent').hide();
                            $('#deptcontent').show();
                            $('#roomcontent').hide();
                            $('#maincontent').hide();
                            str = str.substr(4);
                             var source =
            {
                datatype: "json",
                datafields: [
                     { name: 'ID' },
					 { name: 'SoHieuCBCC' },
                     { name: 'Ho' },
                     { name: 'Ten' },
                     { name: 'TenChucVuHienTai' },
                     { name: 'NgaySinh', type: 'date' },
                     { name: 'GioiTinh' },
                     { name: 'HoKhauThuongTru' },
                     { name: 'DiaChi' }

                ],
                id: 'ID',
                url: '/Pers/GetListPersonsInDepartment/'+str,
                root: 'Rows',
                sort: function () {
                    // update the grid and send a request to the server.
                    $("#jqxgridcontent").jqxGrid('updatebounddata', 'sort');
                }

            };

        var dataAdapter = new $.jqx.dataAdapter(source,
                {
                    downloadComplete: function (data) {
                        source.totalrecords = data.TotalRows;
                    }
                }
            );

        // initialize jqxGrid
        $("#jqxgridcontent1").jqxGrid(
            {
                width: '100%',
                source: dataAdapter,
                theme: 'darkblue',
                columnsresize: true,
                autoheight: true,
                pageable: true,
                virtualmode: true,
                sortable: true,
                rendergridrows: function (params) {
                    return params.data;
                },
                ready: function () {
                    $("#jqxgridcontent1").jqxGrid('hidecolumn', 'ID');
                    //$('#jqxgridcontent').jqxGrid('autoresizecolumns'); 
                     @{ if (Session["Quyen"].ToString() == "2")
                       {
                           @(new HtmlString("$('#jqxgridcontent1').jqxGrid('hidecolumn', 'Delete');"))
                           @(new HtmlString("$('#jqxgridcontent1').jqxGrid('hidecolumn', 'Edit');"))
                       }
                     }
                },
                columns:
                 [
                     
                     // { text: 'IDLyLuan', datafield: 'IDLyLuan', width: 0 },
                      {text: 'Số hiệu', datafield: 'SoHieuCBCC', width: '80px' },
                      { text: 'Họ', datafield: 'Ho', width: '15%' },
                       { text: 'Tên', datafield: 'Ten', width: '7%' },
                       { text: 'Chức Vụ', datafield: 'TenChucVuHienTai', width: '120px' },
                      { text: 'Ngày sinh', datafield: 'NgaySinh', cellsformat: 'dd-MM-yyyy', width: '80px' },
                      { text: 'Giới tính', datafield: 'GioiTinh', width: '40px' },
                      { text: 'Hộ khẩu thường trú', datafield: 'HoKhauThuongTru', width: '20%' },
                      { text: 'Địa chỉ', datafield: 'DiaChi', width: '40%' },
                      { text: 'Del', datafield: 'Delete', columntype: 'button', pinned: true, width: '26px',
                          cellsrenderer: function () {
                              return "Delete"
                          },

                          buttonclick: function (row) {
                              // open the popup window when the user clicks a button.
                              editrow = row;

                              var dataRecord = $("#jqxgridcontent1").jqxGrid('getrowdata', editrow);
                              document.location.href = '/Pers/Delete/' + dataRecord.ID + '/';


                          }
                      },

                      { text: 'Edit', datafield: 'Edit', columntype: 'button', pinned: true, width: '26px',
                          cellsrenderer: function () {
                              return "Edit"
                          },

                          buttonclick: function (row) {
                              // open the popup window when the user clicks a button.
                              editrow = row;

                              var dataRecord = $("#jqxgridcontent1").jqxGrid('getrowdata', editrow);
                              document.location.href = '/Pers/Update/' + dataRecord.ID + '/';


                          }
                      }

                  ]
            });
            //auto resize grid
                        }
                        else if (str.substr(0, 4) == "room") {
                            $('#percontent').hide();
                            $('#roomcontent').show();
                            $('#deptcontent').hide();
                            $('#maincontent').hide();
                            str = str.substr(4);
                                                 var source =
            {
                datatype: "json",
                datafields: [
                     { name: 'ID' },
					 { name: 'SoHieuCBCC' },
                     { name: 'Ho' },
                     { name: 'Ten' },
                     { name: 'TenChucVuHienTai' },
                     { name: 'NgaySinh', type: 'date' },
                     { name: 'GioiTinh' },
                     { name: 'HoKhauThuongTru' },
                     { name: 'DiaChi' }

                ],
                id: 'ID',
                url: '/Pers/GetListPersonsInDepartment/'+str,
                root: 'Rows',
                sort: function () {
                    // update the grid and send a request to the server.
                    $("#jqxgridcontent").jqxGrid('updatebounddata', 'sort');
                }

            };

        var dataAdapter = new $.jqx.dataAdapter(source,
                {
                    downloadComplete: function (data) {
                        source.totalrecords = data.TotalRows;
                    }
                }
            );

        // initialize jqxGrid
        $("#jqxgridcontent2").jqxGrid(
            {
                width: '100%',
                source: dataAdapter,
                theme: 'darkblue',
                columnsresize: true,
                autoheight: true,
                pageable: true,
                virtualmode: true,
                sortable: true,
                rendergridrows: function (params) {
                    return params.data;
                },
                ready: function () {
                    $("#jqxgridcontent2").jqxGrid('hidecolumn', 'ID');
                    //$('#jqxgridcontent').jqxGrid('autoresizecolumns'); 
                     @{ if (Session["Quyen"].ToString() == "2")
                       {
                           @(new HtmlString("$('#jqxgridcontent2').jqxGrid('hidecolumn', 'Delete');"))
                           @(new HtmlString("$('#jqxgridcontent2').jqxGrid('hidecolumn', 'Edit');"))
                       }
                     }
                },
                columns:
                 [
                     
                      {text: 'Số hiệu', datafield: 'SoHieuCBCC', width: '10%' },
                      { text: 'Họ', datafield: 'Ho', width: '15%' },
                       { text: 'Tên', datafield: 'Ten', width: '7%' },
                       { text: 'Chức Vụ', datafield: 'TenChucVuHienTai', width: '15%' },
                      { text: 'Ngày sinh', datafield: 'NgaySinh', cellsformat: 'dd-MM-yyyy', width: '15%' },
                      { text: 'Giới tính', datafield: 'GioiTinh', width: '10%' },
                      { text: 'Hộ khẩu thường trú', datafield: 'HoKhauThuongTru', width: '20%' },
                      { text: 'Địa chỉ', datafield: 'DiaChi', width: '20%' },
                      { text: 'Del', datafield: 'Delete', columntype: 'button', pinned: true, width: '5%',
                          cellsrenderer: function () {
                              return "Delete"
                          },

                          buttonclick: function (row) {
                              // open the popup window when the user clicks a button.
                              editrow = row;

                              var dataRecord = $("#jqxgridcontent2").jqxGrid('getrowdata', editrow);
                               jqxConfirm.alert('Bạn có chắc muốn xóa chức vụ này khỏi danh sách?');  
                                        $("#alert_button").click(function () 
                                        {
                                            document.location.href = '/Pers/Delete/' + dataRecord.ID + '/';
                                            jqxAlert._hide();
                                        });
                              //document.location.href = '/Pers/Delete/' + dataRecord.ID + '/';


                          }
                      },

                      { text: 'Edit', datafield: 'Edit', columntype: 'button', pinned: true, width: '5%',
                          cellsrenderer: function () {
                              return "Edit"
                          },

                          buttonclick: function (row) {
                              // open the popup window when the user clicks a button.
                              editrow = row;

                              var dataRecord = $("#jqxgridcontent2").jqxGrid('getrowdata', editrow);
                              document.location.href = '/Pers/Update/' + dataRecord.ID + '/';


                          }
                      }

                  ]
            });
                        }
                    }
                    return false;
                }
                var rightClick = isRightClick(event);
                if (rightClick && target != null) {
                    $("#jqxTree1").jqxTree('selectItem', target);
                    var scrollTop = $(window).scrollTop();
                    var scrollLeft = $(window).scrollLeft();
                    //switch context menu - phi
                    var ItemContext = $('#jqxTree1').jqxTree('selectedItem');
                    contextMenu.jqxMenu('close'); contextMenu2.jqxMenu('close');
                     var str = ItemContext.id;
                    if (ItemContext != null) {
                        if (str.substr(0, 3) == "per") {
                            contextMenu.jqxMenu('open', parseInt(event.clientX) + 5 + scrollLeft, parseInt(event.clientY) + 5 + scrollTop);
                        }
                        else {
                            contextMenu2.jqxMenu('open', parseInt(event.clientX) + 5 + scrollLeft, parseInt(event.clientY) + 5 + scrollTop);
                        }
                    }
                    //end switch menu - phi
                    //contextMenu.jqxMenu('open', parseInt(event.clientX) + 5 + scrollLeft, parseInt(event.clientY) + 5 + scrollTop);
                    return false;
                }
            });
        }
        attachContextMenu();
        $("#jqxMenu1").on('itemclick', function (event) {
            var item = $.trim($(event.args).text());      
            switch (item) {
                case "Cập nhật hồ sơ":
                    var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                     var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                            document.location.href = '/Pers/Update/' + str;
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
                case "Xóa hồ sơ":
                    var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                        jqxConfirm.alert("Bạn có chắc muốn xóa cán bộ, viên chức này ra khỏi danh sách?");
                        $("#alert_button").click(function () 
                              {
                                            document.location.href = '/Pers/Delete/' + str;
                                            jqxAlert._hide();
                              });
                            
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
                case "Chuyển công tác":
                    var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                            document.location.href = '/ChaDept/Update/' + str;
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
                case "Quan hệ gia đình":
                    var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                            document.location.href = '/Frel/Index/' + str;
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
                case "Hình thức khen thưởng":
                     var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                            document.location.href = '/Bon/Index/' + str;
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
                case "Hình thức kỷ luật":
                     var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                            document.location.href = '/Dis/Index/' +str;
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
                case "Trình độ lý luận":
                    var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                            document.location.href = '/TDRea/Index/' + str;
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
                case "Trình độ ngoại ngữ":
                    var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                            document.location.href = '/Lang/Index/' + str;
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
                case "Trình độ tin học":
                     var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                            document.location.href = '/TDIt/Index/' + str;
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
                case "Trình độ chuyên môn":
                    var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                            document.location.href = '/TDSpe/Index/' + str;
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
                case "Trình độ quản lý nhà nước":
                    var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                            document.location.href = '/TDStateMan/Index/' + str;
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
                case "Quá trình công tác":
                     var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                            document.location.href = '/Process/Index/' + str;
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
                case "Quá trình đào tạo":
                    var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                            document.location.href = '/Trai/Index/' + str;
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
                case "Diễn biến lương":
                    var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                            document.location.href = '/DienBienLuong/Index/' + str;
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
                case "Phụ cấp":
                    var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                            document.location.href = '/AlloDet/Index/' + str;
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
                //truyen them      
                case "Sơ yếu lý lịch":
                   var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    var str = selectedItem.id;
                    if (selectedItem != null) {
                        if (str.substr(0, 3) == "per") {
                        str = str.substr(3);
                            document.location.href = '/aspFrm/frmSYLL.aspx?id=' + str
                            //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                            //attachContextMenu();
                        }
                    }
                    break;
            }
        });
        $("#jqxMenu2").on('itemclick', function (event) {
            var item = $.trim($(event.args).text());
            switch (item) {
                case "Thêm Cán bộ":
                    var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    if (selectedItem != null) {

                        document.location.href = '/Pers/Add/' + selectedItem.id.substring(4) + '/';
                        //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                        //attachContextMenu();

                    }
                    break;
                case "Danh sách cán bộ":
                    var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    if (selectedItem != null) {

                        document.location.href = '/Pers/Index/' + selectedItem.id.substring(4) + '/';
                        //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                        //attachContextMenu();

                    }
                    break;
                case "Danh sách cán bộ(có đơn vị trực thuộc)":
                    var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    if (selectedItem != null) {

                        document.location.href = '/Pers/List/' + selectedItem.id.substring(4) + '/';
                        //$('#jqxTree1').jqxTree('addTo', { label: selectedItem.id }, selectedItem.element);
                        //attachContextMenu();

                    }
                    break;
                case "Remove Item":
                    var selectedItem = $('#jqxTree1').jqxTree('selectedItem');
                    if (selectedItem != null) {
                        $('#jqxTree1').jqxTree('removeItem', selectedItem.element);
                        attachContextMenu();
                    }
                    break;
            }
        });
        // disable the default browser's context menu.
        $(document).on('contextmenu', function (e) {
            if ($(e.target).parents('.jqx-tree').length > 0) {
                return false;
            }
            return true;
        });
        function isRightClick(event) {
            var rightclick;
            if (!event) var event = window.event;
            if (event.which) rightclick = (event.which == 3);
            else if (event.button) rightclick = (event.button == 2);
            return rightclick;
        }
        function isLeftClick(event) {
            var leftclick;
            if (!event) var event = window.event;
            if (event.which) leftclick = (event.which == 1);
            else if (event.button) leftclick = (event.button == 0);
            return leftclick;
        }
    });
    </script>
    
        <div id='jqxWidget1'>@Html.Raw(tree)
        
        <div id='jqxMenu1'>
            <ul>
             @{ 
                if (Session["Quyen"].ToString() == "1")
                {
                <li>Cập nhật hồ sơ</li>
                <li>Xóa hồ sơ</li>
                <li>Chuyển công tác</li>
                }
                }
                <li>Trình độ chuyên môn</li>
                <li>Trình độ lý luận</li>
                <li>Trình độ quản lý nhà nước</li>
                 <li>Trình độ ngoại ngữ</li>
                 <li>Trình độ tin học</li>                 
                <li>Quan hệ gia đình</li>                
                <li>Hình thức khen thưởng</li>
                <li>Hình thức kỷ luật</li>
                <li>Quá trình công tác</li>
                <li>Quá trình đào tạo</li>
                <li>Diễn biến lương</li>
                <li>Phụ cấp</li> 
                 <li>Sơ yếu lý lịch</li>             
            </ul>
        </div>
        <div id='jqxMenu2'>
            <ul> 
            @{ if (Session["Quyen"].ToString() == "1")
                {
                <li>Thêm Cán bộ</li>
                }}
                <li>Danh sách cán bộ</li>
                <li>Danh sách cán bộ(có đơn vị trực thuộc)</li>         
            </ul>
        </div>
     </div>